package com.betterjr.modules.application.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.betterjr.common.annotation.MetaData;
import com.betterjr.common.entity.BetterjrEntity;
import com.betterjr.common.selectkey.SerialGenerator;
import com.betterjr.modules.application.data.AmsMenuInfoConstantCollections;

/**
 * 菜单表
 * @ClassName: AmsMenuInfo 
 * @Description: 菜单表 
 * @author xuyp
 * @date 2017年11月17日 下午3:02:25 
 *
 */
@Access(AccessType.FIELD)
@Entity
@Table(name = "t_ams_menu")
public class AmsMenuInfo implements BetterjrEntity {

    /** 
     * @Fields serialVersionUID :  
     */
    private static final long serialVersionUID = 4919396022220736906L;

    /**
     * 流水号
     */
    @Id
    @Column(name = "ID", columnDefinition = "INTEGER")
    @MetaData(value = "流水号", comments = "流水号")
    private Long id;

    /**
     * 菜单名称
     */
    @Column(name = "c_menu_name", columnDefinition = "VARCHAR")
    @MetaData(value = "菜单名称", comments = "菜单名称")
    private String menuName;

    /**
     * 菜单标题
     */
    @Column(name = "c_menu_title", columnDefinition = "VARCHAR")
    @MetaData(value = "菜单标题", comments = "菜单标题")
    private String menuTitle;

    /**
     * 描述
     */
    @Column(name = "c_description", columnDefinition = "VARCHAR")
    @MetaData(value = "描述", comments = "描述")
    private String description;

    /**
     * 路径
     */
    @Column(name = "c_url", columnDefinition = "VARCHAR")
    @MetaData(value = "路径", comments = "路径")
    private String url;

    /**
     * 是否新开页面 1不开启新页面     2 开启
     */
    @Column(name = "c_target_form", columnDefinition = "VARCHAR")
    @MetaData(value = "是否新开页面", comments = "是否新开页面")
    private String targetForm;

    /**
     * 应用id
     */
    @Column(name = "n_application_id", columnDefinition = "INTEGER")
    @MetaData(value = "应用id", comments = "应用id")
    private Long applicationId;

    /**
     * 菜单顺序，越小越优先
     */
    @Column(name = "n_order", columnDefinition = "INTEGER")
    @MetaData(value = "菜单顺序，越小越优先", comments = "菜单顺序，越小越优先")
    private int orderMenu;

    /**
     * 应用名称
     */
    @Transient
    private String applicationName;

    @Transient
    private List<AmsMenuInfo> childrens = new ArrayList<AmsMenuInfo>();

    /**
     * 资源列表
     */
    @Transient
    private List<AmsResource> resourceList = new ArrayList<AmsResource>();

    @Transient
    private List<AmsResourceExtend> resourceExtendList = new ArrayList<AmsResourceExtend>();

    @Transient
    private String forwardUrl;
    /**
     * 菜单角色
     */
    @Column(name = "c_rule_list", columnDefinition = "VARCHAR")
    @MetaData(value = "菜单角色", comments = "菜单角色")
    private String ruleList;

    /**
     * 菜单状态  1 正常   2失效
     */
    @Column(name = "c_businStatus", columnDefinition = "VARCHAR")
    @MetaData(value = "菜单状态  1 正常   2失效", comments = "菜单状态  1 正常   2失效")
    private String businStatus;

    /**
     * 父菜单
     */
    @Column(name = "n_parent_id", columnDefinition = "INTEGER")
    @MetaData(value = "父菜单", comments = "父菜单")
    private Long parentId;

    /**
     * 是否是叶子节点  1 是   2 不是
     */
    @Column(name = "c_end_node", columnDefinition = "VARCHAR")
    @MetaData(value = "是否是叶子节点  1 是   2 不是", comments = "是否是叶子节点  1 是   2 不是")
    private String endNode;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    public String getMenuTitle() {
        return menuTitle;
    }

    public void setMenuTitle(String menuTitle) {
        this.menuTitle = menuTitle;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getTargetForm() {
        return targetForm;
    }

    public void setTargetForm(String targetForm) {
        this.targetForm = targetForm;
    }

    public Long getApplicationId() {
        return applicationId;
    }

    public void setApplicationId(Long applicationId) {
        this.applicationId = applicationId;
    }

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    public String getRuleList() {
        return ruleList;
    }

    public void setRuleList(String ruleList) {
        this.ruleList = ruleList;
    }

    public String getBusinStatus() {
        return businStatus;
    }

    public void setBusinStatus(String businStatus) {
        this.businStatus = businStatus;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getEndNode() {
        return endNode;
    }

    public void setEndNode(String endNode) {
        this.endNode = endNode;
    }

    public List<AmsResource> getResourceList() {
        return resourceList;
    }

    public void setResourceList(List<AmsResource> resourceList) {
        this.resourceList = resourceList;
    }

    public List<AmsResourceExtend> getResourceExtendList() {
        return resourceExtendList;
    }

    public void setResourceExtendList(List<AmsResourceExtend> resourceExtendList) {
        this.resourceExtendList = resourceExtendList;
    }

    public String getForwardUrl() {
        return url + "?ruleList=" + ruleList;
    }

    public void setForwardUrl(String forwardUrl) {
        this.forwardUrl = url + "?ruleList=" + ruleList;
    }

    public List<AmsMenuInfo> getChildrens() {
        return childrens;
    }

    public void setChildrens(List<AmsMenuInfo> childrens) {
        this.childrens = childrens;
    }

    public int getOrderMenu() {
        return orderMenu;
    }

    public void setOrderMenu(int orderMenu) {
        this.orderMenu = orderMenu;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((applicationId == null) ? 0 : applicationId.hashCode());
        result = prime * result + ((applicationName == null) ? 0 : applicationName.hashCode());
        result = prime * result + ((businStatus == null) ? 0 : businStatus.hashCode());
        result = prime * result + ((description == null) ? 0 : description.hashCode());
        result = prime * result + ((endNode == null) ? 0 : endNode.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((menuName == null) ? 0 : menuName.hashCode());
        result = prime * result + ((menuTitle == null) ? 0 : menuTitle.hashCode());
        result = prime * result + ((parentId == null) ? 0 : parentId.hashCode());
        result = prime * result + ((ruleList == null) ? 0 : ruleList.hashCode());
        result = prime * result + ((targetForm == null) ? 0 : targetForm.hashCode());
        result = prime * result + ((url == null) ? 0 : url.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        AmsMenuInfo other = (AmsMenuInfo) obj;
        if (applicationId == null) {
            if (other.applicationId != null) return false;
        } else if (!applicationId.equals(other.applicationId)) return false;
        if (applicationName == null) {
            if (other.applicationName != null) return false;
        } else if (!applicationName.equals(other.applicationName)) return false;
        if (businStatus == null) {
            if (other.businStatus != null) return false;
        } else if (!businStatus.equals(other.businStatus)) return false;
        if (description == null) {
            if (other.description != null) return false;
        } else if (!description.equals(other.description)) return false;
        if (endNode == null) {
            if (other.endNode != null) return false;
        } else if (!endNode.equals(other.endNode)) return false;
        if (id == null) {
            if (other.id != null) return false;
        } else if (!id.equals(other.id)) return false;
        if (menuName == null) {
            if (other.menuName != null) return false;
        } else if (!menuName.equals(other.menuName)) return false;
        if (menuTitle == null) {
            if (other.menuTitle != null) return false;
        } else if (!menuTitle.equals(other.menuTitle)) return false;
        if (parentId == null) {
            if (other.parentId != null) return false;
        } else if (!parentId.equals(other.parentId)) return false;
        if (ruleList == null) {
            if (other.ruleList != null) return false;
        } else if (!ruleList.equals(other.ruleList)) return false;
        if (targetForm == null) {
            if (other.targetForm != null) return false;
        } else if (!targetForm.equals(other.targetForm)) return false;
        if (url == null) {
            if (other.url != null) return false;
        } else if (!url.equals(other.url)) return false;
        return true;
    }

    @Override
    public String toString() {
        return "AmsMenuInfo [id=" + id + ", menuName=" + menuName + ", menuTitle=" + menuTitle + ", description="
                + description + ", url=" + url + ", targetForm=" + targetForm + ", applicationId=" + applicationId
                + ", orderMenu=" + orderMenu + ", applicationName=" + applicationName + ", childrens=" + childrens
                + ", resourceList=" + resourceList + ", forwardUrl=" + forwardUrl + ", ruleList=" + ruleList
                + ", businStatus=" + businStatus + ", parentId=" + parentId + ", endNode=" + endNode + "]";
    }

    public void saveAddValue() {

        this.setId(SerialGenerator.getLongValue("AmsMenuInfo.id"));
        this.setBusinStatus(AmsMenuInfoConstantCollections.AMSMENUINFO_BUSINSTATUS_EFFECTIVED);
        this.setEndNode("1");
        this.setTargetForm("1");
        this.setOrderMenu(AmsMenuInfoConstantCollections.AMSMENUINFO_ORDERMENU_DEFAULT);

    }

}
